package com.sinosoft.perfect.system._resource.dataFormat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sinosoft.perfect.common.xmlService.XmlInfoBean;
import com.sinosoft.perfect.common.xmlService.XmlProducerDom4j;
import com.sinosoft.perfect.system._.po.TResourceSystem;

public class ResourceGridDataFormat_DHX implements IResourceGridDataFormat {

	@Override
	public String dataFormatResourceGrid(List<TResourceSystem> resourceList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);
		if (resourceList != null && resourceList.size() > 0) {
			for (int i = 0; i < resourceList.size(); i++) {
				TResourceSystem resource = resourceList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(resource.getResourceId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", resource.getResourceId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(resource.getResourceId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(resource.getResourceId());
				cell2.setContent(resource.getResourceName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(resource.getResourceId());
				cell3.setContent(resource.getResourceUrl());
				infos.add(cell3);

				XmlInfoBean cell4 = new XmlInfoBean();
				cell4.setName("cell");
				cell4.setParentId(resource.getResourceId());
				cell4.setContent(resource.getNote());
				infos.add(cell4);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatResourceImgGrid(List<String> resources,String imageWebpath) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);
		if (resources != null && resources.size() > 0) {
			for (int i = 0; i < resources.size(); i++) {
				String resource = resources.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(resource);
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", resource);
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(resource);
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(resource);
				cell2.setContent(imageWebpath+resource);
				infos.add(cell2);
				
				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(resource);
				cell3.setContent(resource);
				infos.add(cell3);

			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

}
